package com.dpstudio.ymprestlful.configuration;


import com.dpstudio.ymprestlful.view.window.options.AppSettingsWindow;
import com.intellij.openapi.options.Configurable;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 * @Author: mengxiang.
 * @Date: 2020/6/22.
 * @Time: 11:37 上午.
 * @Description:
 */
public class YmpRestfulSettingConfigurable implements Configurable {

    private AppSettingsWindow settingsComponent;

    @Nls(capitalization = Nls.Capitalization.Title)
    @Override
    public String getDisplayName() {
        return "YMPRestful Tool";
    }

    @Override
    public JComponent getPreferredFocusedComponent() {
        return settingsComponent.getPreferredFocusedComponent();
    }

    @Nullable
    @Override
    public JComponent createComponent() {
        settingsComponent = new AppSettingsWindow();
        return settingsComponent.getContent();
    }

    @Override
    public boolean isModified() {
        return YmpRestfulSetting.getInstance().isModified(settingsComponent.getAppSetting());
    }

    @Override
    public void apply() {
        YmpRestfulSetting.getInstance().setAppSetting(settingsComponent.getAppSetting());
    }

    @Override
    public void reset() {
        YmpRestfulSetting settings = YmpRestfulSetting.getInstance();
        settingsComponent.setAppSetting(settings.getAppSetting());
    }

    @Override
    public void disposeUIResources() {
        settingsComponent = null;
    }
}
